﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ttifa.Infrastructure.Extensions
{
    public static class ArrayExtensions
    {
        /// <summary>
        /// 从数组中截取一部分成新的数组
        /// </summary>
        /// <param name="source">原数组</param>
        /// <param name="start">原数组的起始位置</param>
        /// <param name="length">长度</param>
        /// <returns></returns>
        public static string[] SplitArray(this string[] source, int start, int length)
        {
            try
            {
                string[] newArray = new string[length];
                for (int i = 0; i < length; i++)
                    newArray[i] = source[i + start];
                return newArray;
            }
            catch (IndexOutOfRangeException ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}
